/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "pico/stdlib.h"
#include "cmsis_os.h"

#define TASK1_STK_SIZE		640
void task1(void *pdata);
osThreadDef(task1, osPriorityNormal, 1, TASK1_STK_SIZE);

//task2
#define TASK2_STK_SIZE		640
void task2(void *pdata);
osThreadDef(task2, osPriorityNormal, 1, TASK2_STK_SIZE);

void task1(void *pdata)
{
    int count = 1;
    while(1)
    {
        printf("\r\nHello world!\r\n###This is task1 ,count is %d \r\n", count++);
        osDelay(2000);
    }
}
void task2(void *pdata)
{
    int count = 1;
    while(1)
    {
        printf("\r\nHello TobudOS !\r\n***This is task2 ,count is %d \r\n", count++);
        osDelay(1000);
    }
}

void SysTick_Handler(void){ 
    if(tos_knl_is_running()){
        tos_knl_irq_enter();
        tos_tick_handler();
        tos_knl_irq_leave();
    }
}

int main() {
    stdio_init_all();
    uart_init(uart0, 115200);
    gpio_set_function(0, GPIO_FUNC_UART);  // TX
    gpio_set_function(1, GPIO_FUNC_UART);  // RX
    stdio_uart_init_full(uart0, 115200, 0, 1);

    osKernelInitialize(); //TOS Tiny kernel initialize
    osThreadCreate(osThread(task1), NULL);// Create task1
    osThreadCreate(osThread(task2), NULL);// Create task2
    osKernelStart();//Start TOS Tiny
    while (true);
}